function myFunction() {
	myVar = setTimeout(function() {
		x_admin_close();
	}, 1500);
};

function myStopFunction() {
	clearTimeout(myVar);
};
var href = window.location.href.split('&');
id = href[1].split('=')[1];

//新增链接
$('#loanlimit').val(href[2].split('=')[1]); //可贷额度
$('#loandeadline').val(href[3].split('=')[1]); //贷款期限
$('#loanrate').val(href[4].split('=')[1]); //还款利率
$('#repaytime').val(href[5].split('=')[1]); //还款时间
$('.select option:selected').text(href[6].split('=')[1]); //还款类型
$('#brand').val(href[7].split('=')[1]); //标签

$("#add").click(function() {

	var loanlimit = $('#loanlimit').val(); //可贷额度
	var loandeadline = $('#loandeadline').val(); //贷款期限
	var loanrate = $('#loanrate').val(); //还款利率
	var repaytime = $('#repaytime').val(); //还款时间
	var repaytype = $('.select option:selected').text(); //还款类型
	var brand = $('#brand').val(); //标签
	var re = /^\d+$/;

	if(loanlimit == '') {

		layer.msg('请输入正确的可贷额度！');
	} else {
		if(loandeadline == '' || loandeadline < 0 || loandeadline > 7 || !re.test(loandeadline)) {
			layer.msg('请输入正确的贷款期限！');
		} else {
			if(loanrate == '' || loanrate < 0.1 || loanrate > 0.5) {
				layer.msg('请输入正确的还款利率！');
			} else {
				if(repaytime == '' || repaytime < 1 || repaytime > 10 || !re.test(repaytime)) {
					layer.msg('请输入正确的还款期限！');
				} else {
					if(repaytype == '请选择') {
						layer.msg('请输入正确的还款类型！');
					} else {
						if(brand == '') {
							layer.msg('请输入正确的产品标签！');
						} else {

							$.post('/api/pro/v1/updatepro.action', {

									productPid: id,
									productMoney: loanlimit,
									productDate: loandeadline,
									productInterest: loanrate,
									productDeadline: repaytime,
									productType: repaytype,
									productLabel: brand
								},
								function(data) {

									if(data.code == 0) {
										layer.msg(data.msg);
										index = parent.index;
										parent.getProduct(index);
										myFunction();
									} else {
										layer.msg(data.msg);
										 myStopFunction();
									}
								});
						}
					}
				}
			}

		}
	}

});